import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/controller/evaluation.dart';
import 'package:ichinesereader/models/assessment/assessmentBookType.dart';
import 'package:ichinesereader/models/assessment/assessmentRecordsResult.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/testRecordGrid.dart';
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import '../../themes/appTheme.dart';

// ignore: must_be_immutable
class EvaluationRecordDataGrids extends StatelessWidget {
  EvaluationRecordDataGrids(this.evaluationRecordItems, this.isTeacher);

  List<QuestionRecord> evaluationRecordItems;
  bool isTeacher = false;

  bool isWebOrDesktop =
      GetPlatform.isMacOS || GetPlatform.isWeb || GetPlatform.isDesktop;
  List<DataGridRow> dataGridRows = <DataGridRow>[];

  EvaluationController _controller = Get.find();
  final box = Hive.box('appconfig');

  @override
  Widget build(BuildContext context) {
    Log.debug('build evaluation records DataGrids');
    return Column(children: [
      Padding(
        padding: const EdgeInsets.only(bottom: 18.0),
        child: FormBuilderChoiceChip(
          alignment: WrapAlignment.end,
          decoration: InputDecoration.collapsed(
            hintText: '',
            border: InputBorder.none,
          ),
          spacing: 6.0,
          elevation: 1,
          backgroundColor:
              Get.isDarkMode ? Get.theme.primaryColor : Colors.grey,
          selectedColor: Get.isDarkMode
              ? Get.theme.primaryColorDark
              : AppTheme.colors.orangeBtn,
          name: 'evaluation_type_chip',
          onChanged: (value) {
            var classId = box.get(CacheManagerKey['currentclass'].toString());
            if (value != null) {
              var eType = value as AssessmentBookType;
              _controller.fetchEvaluationRecords(
                  '0', '0', eType.assessmentType, classId);
            } else {
              _controller.fetchEvaluationRecords('0', '0', '', classId);
            }
          },
          options: Constants.evaluationTypes
              .map((state) => FormBuilderChipOption<AssessmentBookType>(
                    value: state,
                    child: Text(
                      state.displayName.toString(),
                      style: TextStyle(
                          color: Get.isDarkMode
                              ? Colors.black
                              : AppTheme.colors.lightOrange,
                          fontFamily: 'Montserrat'),
                    ),
                  ))
              .toList(),
        ),
      ),
      TestDataRecordGrids(evaluationRecordItems, isTeacher, 'evaluation')
    ]);
  }
}
